﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using FineUI;

namespace lcmyjobs.Web.findjobs
{
    public partial class JobsInfo : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["enterprise_rid"]) && (Application["webid"] != null))
                {
                    int rid = Convert.ToInt32(Request["enterprise_rid"]);
                    if (new lcmyjobs.BLL.enterprise_releasejob().UpdateBcount(rid))
                    {
                        Bind(rid, Convert.ToInt32(Application["webid"]));
                    }

                    this.Title = string.Format("{1}招聘网   {1}人才网   {1}求职网   {1}猎头网  {0}-{2}:{3}", Application["webname"].ToString(), Application["webregion"].ToString(), this.lbl_jobname.Text, this.hy_en.Text);

                }

                // 应聘职位与收藏职位按钮的控制
                if (Session["user_id"] != null)
                {
                    //已登录
                    //btn_login.Visible = false;
                    //lbl_login.Visible = false;
                }
                else
                {
                    //btn_yp.Enabled = false;
                    //btn_collect.Enabled = false;
                    btn_yp.OnClientClick = Win_login.GetShowReference("../popup_userlogin.aspx", "个人用户登录");
                    btn_collect.OnClientClick = Win_login.GetShowReference("../popup_userlogin.aspx", "个人用户登录");
                    //btn_login.OnClientClick = Win_login.GetShowReference("../popup_userlogin.aspx", "个人用户登录");
                }
            }
        }

        private void Bind(int enterprise_rid, int atid)
        {
            DataSet ds = new lcmyjobs.BLL.enterprise_releasejob().GetAllReleaseJob(enterprise_rid, atid);

            DataTable dt_b = ds.Tables[0];
            DataTable dt_m = ds.Tables[2];
            DataTable dt_j = ds.Tables[3];
            DataTable dt_lxfs = ds.Tables[4];

            if (dt_b.Rows.Count > 0)
            {
                this.lbl_bh.Text = enterprise_rid.ToString().PadLeft(5, '0');
                this.lbl_bh1.Text = enterprise_rid.ToString().PadLeft(5, '0');
                this.lbl_about.Text = lcmyjobs.BLL.Tools.RemoveHtml(dt_b.Rows[0]["about"].ToString(),300);
                this.lbl_edu.Text = dt_b.Rows[0]["edu_name"].ToString();
                this.lbl_gwzz.Text = dt_b.Rows[0]["jobduty"].ToString();
                this.lbl_jobdep.Text = dt_b.Rows[0]["jobdep"].ToString();
                this.lbl_jobname.Text = dt_b.Rows[0]["jobs_name"].ToString();
                this.lbl_lan.Text = dt_b.Rows[0]["language_name"].ToString();
                this.lbl_validity.Text = dt_b.Rows[0]["validity"].ToString();
                foreach (DataRow row in dt_m.Rows)
                {
                    this.lbl_major.Text += row["major_name"].ToString() + "  ";
                }

                //this.lbl_name.Text = dt_b.Rows[0]["name"].ToString();
                this.hy_en.Text = dt_b.Rows[0]["name"].ToString();
                this.hy_en.NavigateUrl = "../findjobs/ListVipJobs-" + dt_b.Rows[0]["enterprise_bid"].ToString() + ".html";

                this.lbl_reftime.Text = DateTime.Parse(dt_b.Rows[0]["reftime"].ToString()).ToString("g");
                this.lbl_salarym.Text = lcmyjobs.BLL.Tools.GetSalary(dt_b.Rows[0]["salarym"].ToString());
                this.lbl_workerclass.Text = lcmyjobs.BLL.Tools.GetWorkerclass(dt_b.Rows[0]["workerclass"].ToString());
                this.lbl_workercount.Text = dt_b.Rows[0]["workercount"].ToString();
                this.lbl_workexp.Text = dt_b.Rows[0]["workexpname"].ToString();
                this.lbl_gwyq.Text = dt_b.Rows[0]["jobrequirement"].ToString();

                this.hy_comp_detail.Visible = true;
                this.hy_comp_detail.NavigateUrl = "../findjobs/ListVipJobs-" + dt_b.Rows[0]["enterprise_bid"].ToString() + ".html";
            }

            if (dt_j.Rows.Count > 0)
            {
                this.GridView1.DataSource = dt_j; 
                this.GridView1.DataBind();


            }
            
            /*
            //dt_b.Rows[0]["area_name"] = ds.Tables[1].Rows[0]["area_name"];
            this.GridView1.DataSource = dt_b;
            this.GridView1.DataBind();
            */
            //if (Session["user_id"] == null && Session["enterprise_bid"] == null)
            if (Session["user_id"] == null )
            {
                if (Session["enterprise_bid"] == null)
                {
                    string str = " <img src='../images/lb_06.gif' style='vertical-align:middle;'>&nbsp;<span style='color: #ff6600;'>友情提示：</span><span style='color:#252525'>您尚未登录/注册,暂不能查看该单位的联系方式，点击</span><a style='color:#ff6600' class='login' href='../users/userlogin.html'>登陆</a><span color:#252525>或</span><a style='color:#ff6600' class='login' href='../users/userlogin.html'>注册</a>";

                    this.lti_warn.Text = str;

                    this.Panel1.Visible = false;
                    return;
                }
                else if(dt_b.Rows[0]["enterprise_bid"].ToString() != Session["enterprise_bid"].ToString()){
                    this.lti_warn.Text = "您不是个人会员，暂不能查看该企业联系方式!";
                    this.Panel1.Visible = false;
                    return;
                }
            }

                // 显示企业联系方式
                //string str = " <img src='../images/lb_06.gif' style='vertical-align:middle;'>&nbsp;&nbsp;<span style='color: #ff6600;'>欢迎您：" + Session["user_name"].ToString() + "</span>";
                //this.lti_warn.Text = str;

                if (dt_lxfs.Rows.Count > 0)
                {
                    this.lbl_lxr.Text = dt_lxfs.Rows[0]["lxr"].ToString();
                    this.lbl_mobile_phone.Text = dt_lxfs.Rows[0]["mobilephone"].ToString();
                    this.lbl_telephone.Text = dt_lxfs.Rows[0]["telephone"].ToString();
                    this.lbl_website.Text = dt_lxfs.Rows[0]["website"].ToString();
                    this.lbl_dwdz.Text = dt_lxfs.Rows[0]["address"].ToString();
                    this.lbl_msdz.Text = dt_lxfs.Rows[0]["interviewadd"].ToString();
                    this.lbl_fax.Text = dt_lxfs.Rows[0]["fax"].ToString();
                    this.Panel1.Visible = true;
                }
                else
                {
                    this.Panel1.Visible = false;
                    this.lti_warn.Text = "<br/>您所浏览的单位没有公开联系方式！";
                }
                

            

             
        }



        protected void btn_yp_Click(object sender, EventArgs e)
        {
            if (Session["user_id"] != null)
            {

                if (!string.IsNullOrEmpty(Request["enterprise_rid"]))
                {
                    int rows = 0;
                    try
                    {
                        int id = int.Parse(Request["enterprise_rid"].ToString());
                        int uid = int.Parse(Session["user_id"].ToString());
                        lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
                        if (bub.adduseremp(uid, id, out rows) == 1)
                        {
                            if (rows > 0)
                            {
                                //Maticsoft.Common.MessageBox.Show(this, "应聘成功！");
                                Alert.Show("应聘成功！");
                            }
                            else
                            {
                                //Maticsoft.Common.MessageBox.Show(this, "应聘失败！");
                                Alert.Show("应聘失败！");
                            }

                        }
                        else
                        {
                            //Maticsoft.Common.MessageBox.Show(this, "您已经应聘过该职位！");
                            Alert.Show("您已经应聘过该职位！");
                        }

                    }
                    catch (Exception ex)
                    {

                        //Maticsoft.Common.MessageBox.Show(this, "应聘失败！");
                        Alert.Show("应聘失败！");
                    }
                }
                else
                {
                    //Maticsoft.Common.MessageBox.Show(this, "地址非法！");
                    Alert.Show("地址非法！");

                }
            }
            else
                //Response.Redirect("~/users/userlogin.html");
                ClientScript.RegisterStartupScript(this.GetType(), "a", "if(confirm('您还没有登录！是否要登录？'))window.location='../users/userlogin.html'", true);

        }

        protected void btn_collect_Click(object sender, EventArgs e)
        {
            if (Session["user_id"] != null)
            {

                if (!string.IsNullOrEmpty(Request["enterprise_rid"]))
                {
                    int rows = 0;
                    try
                    {
                        int id = int.Parse(Request["enterprise_rid"].ToString());
                        int uid = int.Parse(Session["user_id"].ToString());
                        lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
                        if (bub.addusercollect(uid, id, out rows) == 1)
                        {
                            if (rows > 0)
                            {
                                //Maticsoft.Common.MessageBox.Show(this, "收藏成功！");
                                Alert.Show("收藏成功！");

                            }
                            else
                                //Maticsoft.Common.MessageBox.Show(this, "收藏失败！");
                                Alert.Show("收藏失败！");


                        }
                        else
                            //Maticsoft.Common.MessageBox.Show(this, "您已经收藏过该职位！");
                            Alert.Show("您已经收藏过该职位！");
                    }
                    catch (Exception ex)
                    {

                        //Maticsoft.Common.MessageBox.Show(this, "收藏失败！");
                        Alert.Show("收藏失败！");
                    }
                }
                else
                {
                    //Maticsoft.Common.MessageBox.Show(this, "地址非法！");
                    Alert.Show("地址非法！");
                }
            }
            else
                //Response.Redirect("~/users/userlogin.html");
                ClientScript.RegisterStartupScript(this.GetType(), "a", "if(confirm('您还没有登录！是否要登录？'))window.location='../users/userlogin.html'", true);

        }


        protected void showloginwindow(object sender, EventArgs e)
        {

        }

        protected void Win_login_Close(object sender, EventArgs e)
        {
        }


    }
}